home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / usr / sybase / sample / dblibrary / installsample < prev    next >
Text File  |  1993-04-22  |  5KB  |  179 lines

  1. #!/bin/csh -f
  2. # installsample
  3. #
  4. # pjs 5/8/90
  5. #
  6. # This script installs a 16M sample dataserver for use in running the DBLib
  7. # sample programs.  The sample database includes the 'pubs' database and 
  8. # enough space to create the 'test' database created by example2.c.  This
  9. # script creates a server login with the user's UNIX login name and password
  10. # 'server_password' which is used by the samples. The user is granted all
  11. # permissions which is required for running the samples.  The remote procedure
  12. # 'rpctest' used in example8.c is created in the database with the user as the
  13. # owner. The script assumes that you have set the SYBASE environment variable
  14. # to the sybase root directory and that is where the interfaces file is located.
  15. # This can be accomplished by running 'source /usr/sybase/SetVars' before running
  16. # installsample.
  17. #
  18. # Usage:
  19. # installsample <db_device_name> [<server_name>]
  20. #
  21. # where db_device_name is the full pathname for the database device to be
  22. # installed. We recommend that you name database devices with a .sdb extension.
  23. # The optional argument server_name is the name of the server when it is
  24. # started.  The default for server_name is SYBASE.
  25. #
  26. # e.g. installsample ~/your_dir/dbs/practice_db.sdb PRACTICE
  27. # will install a 16M database device '~/your_dir/dbs/practice_db.sdb' 
  28. # that has a login with your UNIX login name and password 'server_password'. 
  29. # The script also starts a dataserver named PRACTICE for this device. 
  30. #
  31. # Script internals:
  32. #
  33. # Arguments and environment variables used:
  34. # $1             - the full pathname for the database device
  35. # $2            - server name for server that's going to be started
  36. # $SYBASE        - SYBASE root directory, interfaces file location
  37. # $DSLISTEN        - server name in interfaces file that server "listens to"
  38. # $DSQUERY         - server name in interfaces file that client "speaks to"
  39. #
  40. # Internal variables used:
  41. # $db_device    - the full pathname for the database device
  42. # $user         - user's database login name, user's UNIX login name
  43. # $server_name    - server name for server that's going to be started
  44. # $error        - error flag
  45. # $root            - root directory
  46. # $startserver    - path name for starserver script
  47. # $isql            - path name for isql
  48. #
  49.  
  50. #
  51. # Check to see that the SYBASE, DSLISTEN, and DSQUERY environment variables have
  52. # been set.
  53. #
  54. set error = 0
  55. if !($?SYBASE && $?DSLISTEN && $?DSQUERY) then
  56.   set error = 1
  57.   echo "installsample: Installation failed."
  58.   echo "  You must set the SYBASE, DSLISTEN, and DSQUERY environment variables"          
  59.   echo "  before running installsample. You can most easily do this by running"
  60.   echo "  the command:"
  61. #
  62. # Use SYBASE path if it's set, else default to /usr/sybase for error messages.
  63. #
  64.   if !($?SYBASE) then
  65.     set SYBASE = /usr/sybase
  66.   endif
  67.   echo "    source $SYBASE/scripts/SetVars"
  68. endif
  69.  
  70. #
  71. # Check for database device.
  72. #
  73. if ($#argv < 1) then
  74.   set error = 1
  75.   echo ""
  76.   echo "usage: installsample <database_device> [<server_name>]"
  77.   echo "  For complete instructions on using installsample,"
  78.   echo "  see $SYBASE/sample/dblibrary/README."
  79. endif
  80.  
  81. #
  82. # Bailout if any errors at this point.
  83. #
  84. if ($error == 1) then
  85.   exit 1
  86. endif
  87.  
  88. #
  89. # Set db_device, server_name, and user.
  90. #
  91. set db_device = $1
  92. if ($#argv == 2) then
  93.   set server_name = $2
  94. else
  95.   set server_name = SYBASE
  96. endif
  97. set user = `whoami`
  98.  
  99. #
  100. # Configuration
  101. #
  102. set root            = $SYBASE
  103. set startserver     = $root/install/startserver    
  104. set isql             = $root/bin/isql
  105. set installPubs        = $root/scripts/installpubs
  106.  
  107. #
  108. # Use startserver to build a database device with pathname $2 having
  109. # default size of 16M.  
  110. #
  111. echo "Installing database device $db_device"
  112. echo "with database login $user..."
  113. echo ""
  114. echo "y\n" | $startserver -s$server_name -d$db_device
  115. if ($status == 1) then
  116.   echo ""
  117.   echo "installsample: Installation failed."
  118.   echo "  Could not start server '$server_name'." 
  119.   echo "  See startserver error messages."
  120.   exit 1
  121. endif
  122.  
  123. #
  124. # Install the 'pubs' database.
  125. #
  126. echo ""
  127. echo "Installing the 'pubs' database..."
  128. $isql -Usa -P -S$server_name < $installPubs
  129.  
  130. #
  131. # Create a database login with user name $user having password 'server_password'.
  132. #
  133. echo ""
  134. echo "Creating database login $user..." 
  135. $isql -Usa -P -S$server_name << EOF
  136. sp_addlogin $user, server_password
  137. go
  138. sp_adduser $user
  139. go
  140. grant all to $user
  141. go
  142. exit
  143. EOF
  144.  
  145. #
  146. # Create remote procedure 'rpctest' used by example8.c with $user as owner.
  147. echo ""
  148. echo "Creating remote procedure 'rpctest'..."
  149. $isql -U$user -Pserver_password -S$server_name << EOF
  150. create procedure rpctest
  151.     (@param1 int out,
  152.          @param2 int out,
  153.           @param3 int out,
  154.           @param4 int)
  155.      as
  156.      begin
  157.              select "rpctest is running."
  158.              select @param1 = 11
  159.              select @param2 = 22
  160.              select @param3 = 33
  161.              select @param1
  162.     
  163.              return 123
  164.      end
  165. go
  166. exit
  167. EOF
  168.  
  169. #
  170. # Parting message.
  171. #
  172. echo ""
  173. echo "Installation completed."
  174. echo "  You can now run $SYBASE/sample/dblibrary/exam1-9"
  175. echo "  or run isql using the command:"  
  176. echo "      $SYBASE/bin/isql -U$user -Pserver_password -S$server_name"
  177.  
  178.